package com.example.lianxi222.fragment.video;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.mvvm_base.base.viewmodel.BaseViewModel;
import com.example.mvvm_base.net.Const;
import com.example.mvvm_base.userbean.CommentEntity;
import com.example.mvvm_base.userbean.FollowEntity;
import com.example.mvvm_base.userbean.LikeEntity;
import com.example.mvvm_base.userbean.VideoEntity;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class VideoModelView extends BaseViewModel<VideoRepo> {
   public MutableLiveData<VideoEntity> videoSuccess=new MutableLiveData<>();
   public MutableLiveData<String> videoFailure=new MutableLiveData<>();
    public MutableLiveData<CommentEntity> commentSuccess=new MutableLiveData<>();
    public MutableLiveData<String> commentFailure=new MutableLiveData<>();
   public MutableLiveData<LikeEntity> likeSuccess=new MutableLiveData<>();
    public MutableLiveData<String> likeFailure=new MutableLiveData<>();
    public MutableLiveData<LikeEntity> unLikeSuccess=new MutableLiveData<>();
    public MutableLiveData<String> unLikeFailure=new MutableLiveData<>();
    public MutableLiveData<FollowEntity> followS=new MutableLiveData<>();
    public MutableLiveData<String> followF=new MutableLiveData<>();
    public MutableLiveData<CommentEntity> sendSuccess=new MutableLiveData<>();
    public MutableLiveData<String> sendFailure=new MutableLiveData<>();

    public VideoModelView(@NonNull Application application) {
        super(application);
    }
   public void getVideo(int page,int size){
        repo.getFragmentVideo(page,size,videoSuccess,videoFailure);
   }
   public void getComment(int id){
        repo.getComment(id,commentSuccess,commentFailure);
   }
    public void like(int id){
        repo.like(id,likeSuccess,likeFailure);
    }
    public void unLike(int id){
        repo.unLike(id,unLikeSuccess,unLikeFailure);
    }
    public void follow(String name){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTH_NAME,name);
        String json=new Gson().toJson(map);
        RequestBody requestBody=RequestBody.create(MediaType.parse("application/json;charset=utf-8"),json);
        repo.follow(requestBody,followS,followF);
    }
    public void send(String name,int id){
        HashMap<String, Object> map = new HashMap<>();
        map.put(Const.PARAM_MSG,name);
        map.put(Const.PARAM_ID,id);
        String json=new Gson().toJson(map);
        RequestBody body=RequestBody.create(MediaType.parse("application/json;charset=utf-8"),json);
        repo.sendMessage(body,sendSuccess,sendFailure);


    }
    @Override
    protected VideoRepo createRepo() {
        return new VideoRepo();
    }
}
